SView Help Center
English (US)

Listening to SView Messages

Author: sviewngts Last Updated: 2026-10-29 15:41

Listening Messages

   1. To add message listening, you can use the message callback function already added in sview.html5.js under the js folder of the SView for HTML5 package, that is, the update method;just add new case types in it;
   2. Or add message listening directly; note that message listening needs to be added in a class.Refer to the following code:

class MessageListener{
    frame = null;
    constructor(frame){
        this.frame = frame;
        //This indicates that you should listen for frame messages yourself; the messages you typically need are usually forwarded from the frame.
        M3D.Utility.M3DMessageCenter.getCenter().subscribe(this, this.frame);
    }
    update(msg){
        switch(msg.type){
            case M3D.Utility.MessageType.Selector:
            break;
        }
    }
}
new MessageListener(frame);

Listening to Selector Messages

   The commonly used selector messages are add, remove, and clear messages. Add the corresponding case in the update method above. The code is as follows:

case M3D.Utility.MessageType.Selector:
{
    //The array of Shape objects added, removed, or cleared in the selector
    let shapes = msg.shapes;
    if(msg.state === M3D.Utility.OperaState.Add){
        //Add
    }else if(msg.state === M3D.Utility.OperaState.Remove){
        //Remove
    }else if(msg.state === M3D.Utility.OperaState.Clear){
        //Clear
    }
}
break;

Listening to Reader Messages

   The commonly used reader messages are message progress listening and read exception listening.The code is as follows:

case M3D.Utility.MessageType.Read:
{
	if(msg.progress === 100){
		//A progress of 100 means the reading is complete
	}else if(msg.exception){
		//An exception in msg indicates that the reading encountered an exception
	}
}
break;

Listening for Loader Messages

   Loader messages are typically used to listen for messages indicating that each type of additional data has finished loading. The code is as follows:

case M3D.Utility.MessageType.Loader:
{
	if (msg.state === M3D.Utility.OperaState.End) {
		if (msg.loadType == M3D.FILE_MODELVIEW) {
			// View data loaded
		} else if (msg.loadType === M3D.FILE_PMI) {
			// PMI data loaded
		}
	}
}