コード例 #1
0
  public void commandAction(Command c, Displayable d) {
    if (c == startCmd) {
      form.deleteAll();
      form.removeCommand(startCmd);
      form.addCommand(byeCmd);

      Thread t =
          new Thread() {

            public void run() {
              startSession();
            }
          };
      t.start();

      //	    startSession();
      return;
    } else if (c == exitCmd) {
      destroyApp(true);
      return;
    } else if (c == byeCmd) {
      form.removeCommand(byeCmd);
      form.addCommand(restartCmd);
      sendBYE();
      return;
    } else if (c == restartCmd) {
      stopListener();
      form.removeCommand(restartCmd);
      form.addCommand(startCmd);
      form.deleteAll();
      form.append(address);
      return;
    }
  }
コード例 #2
0
  /** Handle incoming response here */
  public void notifyResponse(SipClientConnection scc) {
    int statusCode = 0;
    boolean received = false;
    try {
      scc.receive(0); // <i><b>fetch resent response</b></i>
      statusCode = scc.getStatusCode();
      str = new StringItem("Response: ", statusCode + " " + scc.getReasonPhrase());
      form.append(str);
      if (statusCode < 200) {
        dialog = scc.getDialog();
        form.append("Early-Dialog state: " + dialog.getState());
      }
      if (statusCode == 200) {
        String contentType = scc.getHeader("Content-Type");
        String contentLength = scc.getHeader("Content-Length");
        int length = Integer.parseInt(contentLength);
        if (contentType.equals("application/sdp")) {
          //
          // <i><b>handle SDP here</b></i>
          //
        }
        dialog = scc.getDialog(); // <i><b>save dialog info</b></i>
        form.append("Dialog state: " + dialog.getState());

        scc.initAck(); // <i><b>initialize and send ACK</b></i>
        scc.send();
        str = new StringItem("Session established: ", scc.getHeader("Call-ID"));
        form.append(str);
        scc.close();
      } else if (statusCode >= 300) {
        str = new StringItem("Session failed: ", scc.getHeader("Call-ID"));
        form.append(str);
        form.removeCommand(byeCmd);
        form.addCommand(restartCmd);
        scc.close();
      }
    } catch (IOException ioe) {
      // <i><b>handle e.g. transaction timeout here</b></i>
      str = new StringItem("No answer: ", ioe.getMessage());
      form.append(str);
      form.removeCommand(byeCmd);
      form.addCommand(restartCmd);
    }
  }
コード例 #3
0
 public void notifyRequest(SipConnectionNotifier sn) {
   try {
     ssc = scn.acceptAndOpen(); // <i><b>blocking</b></i>
     if (ssc.getMethod().equals("BYE")) {
       // <i><b>respond 200 OK to BYE</b></i>
       ssc.initResponse(200);
       ssc.send();
       str = new StringItem("Other side hang-up!", "");
       form.append(str);
     }
     form.append("Closing notifier...");
     form.removeCommand(byeCmd);
     form.addCommand(restartCmd);
     scn.close();
   } catch (IOException ex) {
     // <i><b>handle IOException</b></i>
   }
 }